<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 美妆课堂
 * 
 * @author  : $Author: spike $
 * @date    : $Date: 2014-03-03 15:15:37 +0800 (一, 2014-03-03) $
 * @version : $Id: beauty_model.php 41 2014-03-03 07:15:37Z spike $
 * @rev     : $Revision: 41 $
 */
class Beauty_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    // --------------------------------------------------------------------

    /**
     * [获得一个美妆课堂]
     * @param  [string]     $beauty_id
     * @param  [bool]       $enable        [是否排除"关闭状态"]
     * @return [array/false]
     */
    public function get_beauty($beauty_id, $enable = TRUE, $with_detail_img = FALSE)
    {
        if( ! validate($beauty_id, 'BEAUTY_ID') )
        {
            $this->set_error("获取美妆课堂失败：ID格式不正确。[{$beauty_id}]");
            return FALSE;
        }
        
        $where = array(
            'beauty_id'  => $beauty_id,
            'is_delete'  => UNDELETED,
        );
        if($enable === TRUE)
        {
            $where['status'] = BEAUTY_STATUS_ON;
        }

        $this->load->dao('Beauty_dao');
        $beauty = $this->Beauty_dao->get_one($where);
        $beauty['desc'] = htmlspecialchars_decode($beauty['desc']);
        if( ! $beauty)
        {
            $this->set_error("获取美妆课堂失败：无法找到美妆课堂。[{$beauty_id}]");
            return FALSE;
        }

        if($with_detail_img === TRUE)
        {
            $this->load->dao('Beauty_detail_dao');
            $beauty['detail_img'] = $this->Beauty_detail_dao->get(array(
                'beauty_id' => $beauty_id,
                'is_delete' =>UNDELETED,
            ));
        }

        return $beauty;
    }
}
